package com.chenzhiling.fs.objectStorage;

import org.apache.hadoop.fs.PositionedReadable;
import org.apache.hadoop.fs.Seekable;

import java.io.ByteArrayInputStream;
import java.io.IOException;

/**
 * @Author: CHEN ZHI LING
 * @Date: 2021/9/30
 * @Description: ceph对象存储 输入流
 */
public class CephObjectInputStream extends ByteArrayInputStream implements Seekable, PositionedReadable {
    public CephObjectInputStream(byte[] buf) {
        super(buf);
    }

    @Override
    public int read(long position, byte[] buffer, int offset, int length) throws IOException {
        System.arraycopy(buf, (int) position, buffer, offset, length);
        return length;
    }

    @Override
    public void readFully(long position, byte[] buffer, int offset, int length) throws IOException {
        read(position, buffer, offset, length);
    }

    @Override
    public void readFully(long position, byte[] buffer) throws IOException {
        read(position, buffer, 0, buffer.length);
    }

    @Override
    public void seek(long pos) throws IOException {
        reset();
        skip(pos);

    }

    @Override
    public long getPos() throws IOException {
        return pos;
    }

    @Override
    public boolean seekToNewSource(long targetPos) throws IOException {
        return false;
    }

}
